﻿Imports System.Threading
Imports System.Globalization

Public Class CookieLocalizationModule
    Implements IHttpModule

    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

    End Sub

    Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
        AddHandler context.BeginRequest, AddressOf context_BeginRequest
    End Sub

    Private Sub context_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        If (Not HttpContext.Current.Request.Cookies("lang") Is Nothing) Then
            Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies("lang")
            Dim lang As String = cookie.Value
            Dim culture As CultureInfo = New CultureInfo(lang)
            Thread.CurrentThread.CurrentCulture = culture
            Thread.CurrentThread.CurrentUICulture = culture
        End If
    End Sub


End Class
